<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>DemoOfFilter</title>
</head>
<body>

<p>点击按钮获取数组中大于 18 的所有元素。</p>
<button onclick="myFunction()">点我</button>
<p id="demo"></p>
<script>
var ages = [32, 33, 16, 40];
function myFunction() {
    document.getElementById("demo").innerHTML = ages.filter( (age)=> {return age>=18});
}
</script>

</body>
</html>